package cs4383;

import javax.media.j3d.Background;
import javax.media.j3d.Behavior;
import javax.media.j3d.Node;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Vector3d;

import jp.nyatla.nyartoolkit.NyARException;
import jp.nyatla.nyartoolkit.core.NyARCode;
import jp.nyatla.nyartoolkit.java3d.utils.J3dNyARParam;
import jp.nyatla.nyartoolkit.java3d.utils.NyARSingleMarkerBehaviorHolder;

import com.sun.j3d.utils.geometry.ColorCube;

public class Marker {
	private TransformGroup tg = new TransformGroup();
	private Transform3D mt = new Transform3D();
	private Node node = null;
	private Furniture f = null;
	private Background bg;
	private NyARSingleMarkerBehaviorHolder bHolder;
	
	public Marker(Background bg, J3dNyARParam ar_param, NyARCode ar_code) throws NyARException{
		this.bg = bg;
		tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		node = new ColorCube(20 * 0.001);
		tg.addChild(node);
		
		mt.setTranslation(new Vector3d(0.00, 0.0, 20 * 0.001));
		tg.setTransform(mt);
		
		bHolder = new NyARSingleMarkerBehaviorHolder(ar_param, 30f, ar_code, 0.08);
		//Behaviorに連動するグループをセット
		bHolder.setTransformGroup(tg);
		bHolder.setBackGround(bg);

	}
	
	public void setFurniture(Furniture f){
		if(node != null){
			tg.removeChild(node);
		}
		tg.addChild(f.getBranchGroup());
		node = f.getBranchGroup();
		this.f = f;
	}
	
	public TransformGroup getTransformGroup(){
		return tg;
	}
	
	public Behavior getBehavior(){
		return bHolder.getBehavior();
	}
	
	public void startCapture() throws NyARException{
		bHolder.start();
	}
}
